﻿using ICMS.PluginInterfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using commonImportPlugin.Config;
using commonImportPlugin.Common;
using commonImportPlugin.FilesCore.TrackFile;
using commonImportPlugin.Configs.TrackFile;

namespace commonImportPlugin.Factorys
{   
    //
    //  抽象工厂
    //
    #region
    /// <summary>
    /// 磁条工厂类
    /// </summary>
    public abstract class AbstractTrackFile
    {
        public abstract TrackFileCore CreateTrackFileCore(params object[] list);
    }
    public abstract class TrackFileCore
    {
        public abstract List<ICData> GetTrackAllDatas(List<string> trackFilePaths, out int trackCounts);
        public abstract int GetTrackAllCounts(List<string> trackFilePaths);
        public abstract bool CheckTrackData();
    }
    #endregion

    //
    //  各种工厂类集
    //
    #region
    /// <summary>
    /// 普通模式（根据分割符切换再获取）
    /// </summary>
    public class TrackFileCoreFactory : AbstractTrackFile
    {
        public override TrackFileCore CreateTrackFileCore(params object[] list)
        {
            TrackCoreGeneralClass core = new TrackCoreGeneralClass();
            return core.GetInstance();
        }
    }

    /// <summary>
    /// 正则模式（根据根据正则匹配获取）
    /// </summary>
    public class TrackFileCoreRegexFactory : AbstractTrackFile
    {
        public override TrackFileCore CreateTrackFileCore(params object[] list)
        {
            TrackCoreRegexClass core = new TrackCoreRegexClass();
            return core.GetInstance();
        }
    }
    #endregion

    //
    //  简单工厂
    //
    #region
    /// <summary>
    /// 磁条简单工厂
    /// </summary>
    public class setTrackFileCoreFactory
    {
        public TrackFileCore CreateFactory(string whichFatory)
        {
            switch (whichFatory)
            {
                case "General":
                    //初始化配置
                    TrackFileConfig trackFileConfig = new TrackFileConfig();
                    trackFileConfig.Init();
                    //返回初始化核心
                    return new TrackFileCoreFactory().CreateTrackFileCore();
                case "Regex":
                    //初始化配置
                    TrackFileConfigRegex trackFileConfigRegex = new TrackFileConfigRegex();
                    trackFileConfigRegex.Init();
                    //返回初始化核心
                    return new TrackFileCoreRegexFactory().CreateTrackFileCore();
                default:
                    break;
            }
            return null;
        }
    }
    #endregion

}
